﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true"
    CodeBehind="EmployeeList.aspx.cs" Inherits="SapB1WebPOS.EmployeeList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PopupContent" runat="server">
    <script type="text/javascript">
        var keySearch;
        var grid;
        function Search() {
            keySearch = $("#KeySearch").val();
            grid.dataSource.read();
        }
        function onChange(arg) {
            var selectedRows = this.select();
            var selectedDataItems = [];
            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = this.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem);
            }
            if (selectedDataItems.length > 0) {
                parent.ChooseEmployee(selectedDataItems[0].empID, selectedDataItems[0].firstName,
                 selectedDataItems[0].lastName);
            }
        }
        $(document).ready(function () {
            setTimeout(function () { $("#KeySearch").focus(); }, 1);
            keySearch = $("#KeySearch").val();
            $("#KeySearch").keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    Search();
                    return false;
                }
            });
            grid = $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "EmployeeList.aspx/GetList",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (options, operation) {
                            if (operation === "read") {
                                return { keySearch: kendo.stringify(keySearch) };
                            }
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    pageSize: 1000,
                    type: "json",
                    schema: {
                        data: function (response) {
                            if (response.d != null) {
                                var data = response.d;
                                return JSON.parse(data);
                            }
                        },
                        total: function (response) {
                            return JSON.parse(response.d).length;
                        },
                        model: {
                            id: "empID",
                            fields: {
                                empID: { type: "string" },
                                firstName: { type: "string" },
                                lastName: { type: "string" }
                            }
                        }
                    }
                },
                change: onChange,
                sortable: true,
                pageable: {
                    refresh: true
                },
                filterable: true,
                reorderable: true,
                resizable: true,
                height: 400,
                selectable: "row",
                batch: true,
                columns: [{ field: "empID", title: "ID", width: 150 },
                            { field: "firstName", title: "First Name" },
                              { field: "lastName", title: "Last Name", width: 150 }
                            ]
            }).data("kendoGrid");
        });
    </script>
    <table style="width: 100%;" border="0">
        <tr>
            <td style="width: 85%;">
                <input type="text" class="k-input k-textbox" name="KeySearch" id="KeySearch" style="width: 100%;" />
            </td>
            <td align="right">
                <button type="button" id="btnSave" onclick="Search();" class="k-button k-button-icontext k-primary"
                    style="width: 150px;">
                    <span class="k-icon k-i-search"></span>Find</button>
            </td>
        </tr>
    </table>
    <br />
    <div id="grid">
    </div>
</asp:Content>
